<template>
  <el-form-item :label="label" :required="required">
    <el-input-number
      v-model="modelValue"
      :min="min"
      :max="max"
      :step="1"
      :precision="0"
      :disabled="disabled"
      @change="handleChange"
    />
  </el-form-item>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'IntControl',
  props: {
    modelValue: {
      type: Number,
      default: 0
    },
    label: {
      type: String,
      default: ''
    },
    required: {
      type: Boolean,
      default: false
    },
    min: {
      type: Number,
      default: -Infinity
    },
    max: {
      type: Number,
      default: Infinity
    },
    disabled: {
      type: Boolean,
      default: false
    }
  },
  emits: ['update:modelValue'],
  setup(props, { emit }) {
    const handleChange = (value: number) => {
      emit('update:modelValue', value)
    }

    return {
      handleChange
    }
  }
})
</script>